<template>
{{#if ctrl.psSysPFPlugin}}
    {{> @macro/plugins/widget/widget-use.hbs appPlugin=ctrl.psSysPFPlugin}}
{{else}}
  <AppExpBar 
    :class="classNames">
{{#if ctrl.showTitleBar}}
    <template #titleBar>
      <div class="control-header__left__caption">
  {{#if ctrl.psSysImage}}
    {{#if ctrl.psSysImage.imagePath}}
        <img src="{{ctrl.psSysImage.imagePath}}"/>
    {{/if}}
    {{#if ctrl.psSysImage.cssClass}}
        <i class="{{ctrl.psSysImage.cssClass}}"></i>
    {{/if}}
  {{/if}}
        <span class="text">\{{model.title}}</span>
      </div>
    </template>
{{/if}}
{{#and ctrl.parent ctrl.parent.enableQuickGroup ctrl.parent.quickGroupPSCodeList}}
    <template #quickGroup>
        <div class="quick-group-container">
            {{> @macro/common/quick-group.hbs}}
        </div>
    </template>
{{/and}}
{{#if ctrl.enableSearch}}
    <template #quickSearch>
        {{> @macro/common/quick-search.hbs}}
    </template>
{{/if}}
{{#ctrl.ctrls}}
  {{#eq controlType 'TOOLBAR'}}
    <template #toolbar>
      <AppToolbar
        name="toolbar"
        :items="toolbarItems"
        @item-click="(name: string, event: MouseEvent, logic: any) => { handleToolbarItemClick(controller, name, event, logic) }">
      </AppToolbar>
    </template>
  {{/eq}}
{{/ctrl.ctrls}}
    <template #default>
{{#ctrl.ctrls}}
  {{#eq controlType "GRID"}}
      <{{codeName}}Grid
        name="{{name}}"
        :actions="{
          createAction: '{{#and createPSControlAction createPSControlAction.psAppDEMethod}}{{createPSControlAction.psAppDEMethod.codeName}}{{else}}Create{{/and}}',
          fetchAction: '{{#and fetchPSControlAction fetchPSControlAction.psAppDEMethod}}{{fetchPSControlAction.psAppDEMethod.codeName}}{{else}}FetchDefault{{/and}}',
          removeAction: '{{#and removePSControlAction removePSControlAction.psAppDEMethod}}{{removePSControlAction.psAppDEMethod.codeName}}{{else}}Remove{{/and}}',
          updateAction: '{{#and updatePSControlAction updatePSControlAction.psAppDEMethod}}{{updatePSControlAction.psAppDEMethod.codeName}}{{else}}Update{{/and}}'
        }"
        :context="context"
        :viewParams="viewParams"
        :openView="openView"
        :newView="newView"
        :closeView="closeView"
        :selectFirstDefault="true"
        :singleSelect="true"
        :pViewCtx="store.viewCtx"
        @ctrl-init="(name, ability) => { handleCtrlInit(controller, name, ability) }"
        @ctrl-action="(name, action, data) => { handleCtrlAction(controller, name, action, data) }"
        @ctrl-destroy="(name, data) => { handleCtrlDestroy(controller, name, data) }"
      ></{{codeName}}Grid>
  {{/eq}}
{{/ctrl.ctrls}}
    </template>
  </AppExpBar>
{{/if}}
</template>
<script setup lang="ts">
// 基于template/src/widgets/\{{appEntities}}/\{{ctrls@GRIDEXPBAR}}-grid-exp-bar/\{{ctrls@GRIDEXPBAR}}-grid-exp-bar.vue.hbs生成
{{> @macro/plugins/widget/widget-import.hbs ctrl=ctrl}}
{{#ctrl.ctrls}}
  {{#eq controlType "GRID"}}
import {{codeName}}Grid from '@widgets/{{spinalCase appEntity.codeName}}/{{spinalCase codeName}}-grid/{{spinalCase codeName}}-grid.vue';
  {{/eq}}
  {{#eq controlType 'TOOLBAR'}}
import { AppToolbar } from '@components/widgets/toolbar';
  {{/eq}}
{{/ctrl.ctrls}}
import { AppExpBar } from '@components/widgets/exp-bar';
import { GridExpBarActionType, GridExpBarController, IContext, IGridExpBarAbility, IGridExpBarControllerParams, IGridExpBarStore, IParam, IGridExpBarController, ILoadingHelper, createUUID, IViewCtx } from '@/core';
import {
  useNavParamsBind,
  useEventBind,
  getExpBarClassNames,
{{#ctrl.ctrls}}
  {{#eq controlType 'TOOLBAR'}}
  handleToolbarItemClick,
  {{/eq}}
{{/ctrl.ctrls}}
{{#and ctrl.parent ctrl.parent.enableQuickGroup ctrl.parent.quickGroupPSCodeList}}
  handleQuickGroupValueChange,
{{/and}}
{{#if ctrl.enableSearch}}
  handleQuickSearch,
{{/if}}
  handleCtrlInit,
  handleCtrlAction,
  handleCtrlDestroy
} from '@/hooks/use-ctrl';
import { model{{#ctrl.ctrls}}{{#eq controlType 'TOOLBAR'}}, toolbarItems{{/eq}}{{/ctrl.ctrls}} } from './{{spinalCase ctrl.codeName}}-grid-exp-bar-model';
{{> @macro/widgets/ctrl/ctrl-props.hbs
    props="openView?: Function;
    newView?: Function;
    "
}}

{{> @macro/common/emit.hbs name="ctrl" actionType="GridExpBarActionType" ability="IGridExpBarAbility"}}

const classNames = computed(() => {
  return getExpBarClassNames(model, props);
});

const controlID = createUUID();

const params: IGridExpBarControllerParams<GridExpBarActionType, IGridExpBarAbility> = {
  name: props.name,
  model,
  evt,
  controlID,
  openView: props.openView,
  newView: props.newView,
  closeView: props.closeView,
  pViewCtx: props.pViewCtx,
  handler: (data: IGridExpBarStore) => { return reactive(data); }
};
// 表格导航栏控制器
const controller: IGridExpBarController<IGridExpBarStore, IGridExpBarAbility> = new GridExpBarController(params);
useNavParamsBind(controller, props);

const store: IGridExpBarStore = controller.getStore();

onMounted(() => {
  controller.ctrlMounted();
});
onUnmounted(() => {
  controller.ctrlDestroy();
})
</script>